
package uoc.biblioteca.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import uoc.biblioteca.mappings.dao.UserHome;
import uoc.biblioteca.mappings.object.UserVo;
import uoc.biblioteca.struts.form.UserEditForm;
import uoc.biblioteca.struts.form.UserListForm;

/** 
 * MyEclipse Struts
 * Creation date: 07-27-2005
 * 
 * XDoclet definition:
 * @struts:action path="/custeromList" name="custeromListForm" input="/jsp/custeromList.jsp" scope="request"
 * @struts:action-forward name="showCustomerList" path="/jsp/customerList.jsp"
 */
public class UserListAction extends BaseAction {

	// --------------------------------------------------------- Instance Variables

	// --------------------------------------------------------- Methods

	private static final Log log = LogFactory.getLog(UserListAction.class);
	
	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) {
    
		
		UserEditForm  userEditForm = (UserEditForm ) form;
		
			try{
				
				 //Comprobar si la session esta guardada
				UserVo userLogin = obtenerUserSession(request);
				if(userLogin==null){
					request.getSession().setAttribute("ERROR","\n" +NO_USER_SESSION);
					return mapping.findForward("errorNotUser");
				}
				
				UserHome userHome = new UserHome();
				
				userEditForm.setUsers(userHome.getAllUsers());
				
			
			}
			catch (Exception e) {
				e.printStackTrace();
				log.error("Error en UserListAction", e);
			}
				
			return mapping.findForward("usersList");
	}

}

